/*
 * @Date: 2021-11-23 23:18:38
 * @LastEditors: xiaolan
 * @LastEditTime: 2021-11-23 23:19:53
 * @FilePath: \pms\web\document_manage\edit.js
 */

jQuery(document).ready(function() {
  showPage();
  getFileRecordDatatable();
});

var module="../project_documents";
var sub="file";
var user_role = sessionStorage.getItem('user_role');
var user_id=sessionStorage.getItem('user_id');  // 通过全局session获取用户唯一id，可用于后续的权限管理
// 显示界面
function showPage() {
  let user_manage = document.getElementById('user_manage')
  let project_manage = document.getElementById('project_manage')
  let money = document.getElementById('money')
  let contract = document.getElementById('contract')
  if (user_role == '组员') {
    user_manage.style.display = 'none'
    project_manage.style.display = 'none'
    money.style.display = 'none'
    contract.style.display = 'none'
  }
}

var reslutList=[];
var getFileRecordDatatable=function (){
  reslutList=[];
  $('.datatable').dataTable({
    "autoWidth": true,
    "paging":true,
    "searching":true,
    "aaSorting": [], //不让其按第一列排序
    "oLanguage": {
      "aria": {
        "sortAscending": ": activate to sort column ascending",
        "sortDescending": ": activate to sort column descending"
      },
      "sProcessing":   "处理中...",
      "sLengthMenu":   "_MENU_ 记录/页",
      "sZeroRecords":  "没有匹配的记录",
      "sInfo":         "显示第 _START_ 至 _END_ 项记录，共 _TOTAL_ 项",
      "sInfoEmpty":    "显示第 0 至 0 项记录，共 0 项",
      "sInfoFiltered": "(由 _MAX_ 项记录过滤)",
      "sInfoPostFix":  "",
      "sSearch":       "请输入查询信息:",
      "oPaginate": {
        "sFirst":    "首页",
        "sPrevious": "上页",
        "sNext":     "下页",
        "sLast":     "末页"
      }
    },
    "aoColumns": [{"mRender": function(data, type, full) {
        sReturn = '<input type="checkbox" class="checkboxes" value="'+full.id+'"/>';
        return sReturn;
      },"orderable": false
    },
      {"mRender": function(data, type, full) {
          sReturn = '<div>'+full.title+'</div>';
          return sReturn;
        },"orderable": false},
      {"mRender": function(data, type, full) {
          sReturn = '<div>'+full.create_user_id+'</div>';
          return sReturn;
        },"orderable": false},
      {"mRender": function(data, type, full) {
          sReturn = '<div>'+full.create_time+'</div>';
          return sReturn;
        },"orderable": true},
      {"mRender": function(data, type, full) {
          sReturn = '<div>'+full.modify_time+'</div>';
          return sReturn;
        },"orderable": false},
      {"mRender": function(data, type, full) {
          sReturn = '<div>'+full.modify_user+'</div>';
          return sReturn;
        },"orderable": false},
      {"mRender": function(data, type, full) {
          sReturn = '<div>'+full.standardized_title+'</div>';
          return sReturn;
        },"orderable": false},
      {"mRender": function(data, type, full) {
          sReturn = '<div>'+full.type+'</div>';
          return sReturn;
        },"orderable": false},
      {"mRender": function(data, type, full) {
          var url=full.attachment_url;
          if(url.substring(0,1)=="/") url=url.substring(1,url.length);		//去掉最前头的“/”,注意这里新的url，要么为../，不要自己加字母，因为这样不对
          sReturn = '<div><a href=../'+url+' target="_blank">查看文件</a></div>';
          return sReturn;
        },"orderable": false}],
    "aLengthMenu": [[5,10,15,20,25,40,50,-1],[5,10,15,20,25,40,50,"所有记录"]],
    "fnDrawCallback": function(){$(".checkboxes").uniform();$(".group-checkable").uniform();},
    "sAjaxSource": ""+module+"_"+sub+"_servlet_action?action=get_file_information_record&want_attachment=yes&user_id="+user_id
  });
  $('.datatable').find('.group-checkable').change(function () {
    var set = jQuery(this).attr("data-set");
    var checked = jQuery(this).is(":checked");
    jQuery(set).each(function () {
      if (checked) {
        $(this).attr("checked", true);
        $(this).parents('tr').addClass("active");
      } else {
        $(this).attr("checked", false);
        $(this).parents('tr').removeClass("active");
      }
    });
    jQuery.uniform.update(set);
  });
  $('.datatable').on('change', 'tbody tr .checkboxes', function () {
    $(this).parents('tr').toggleClass("active");
  });
};
